
const views = import.meta.glob('../views/**/*.vue')


 export function createRoutes() {
    const viewRoute = []
    Object.entries(views).forEach(([file, module]) => {
        const path = getPath(file)
        if (path) {
            const route = {
                name: path,
                path: path,
                component: loadComponent(path)
            }
            viewRoute.push(route)
        }
    })

    return viewRoute
}

const loadComponent = (component) => {
    if (component) {
        return  views[`../views/${component}/index.vue`]
    } else {
        // return () => import(/* @vite-ignore */ `/src/layout/other/empty.vue`)
    }
}

function getPath(path) {
    // 判断路径是否以 ../views/ 开头
    if (!path.startsWith("../views/")) {
        return "";
    }

    // 判断路径是否以 /index.vue 结尾
    if (!path.endsWith("/index.vue")) {
        return "";
    }
    // 获取路径的开头部分
    const start = path.indexOf("../views/") + 9;
    // 获取路径的结尾部分
    const end = path.indexOf("/index.vue");

    // 返回中间部分
    return path.slice(start, end);
}



